from  time import sleep
from selenium import webdriver
from selenium.webdriver.edge.service import Service
from selenium.webdriver.common.by import By
from lxml import etree

service = Service()
service.path = r'chromedriver.exe'
# 启动浏览器
browser = webdriver.Chrome(service=service)

# 让浏览器发起一个指定url对应请求
browser.get('https://www.taobao.com/')

# 标签定位
search_input = browser.find_element(By.ID,'q')

# 标签交互
search_input.send_keys('iphone')

# 执行一组js程序
browser.execute_script('window.scrollTo(0,document.body.scrollHeight)')

sleep(2)

# css选择器
button = browser.find_element(By.CSS_SELECTOR,'.btn-search')

button.click()


browser.get('https://www.baidu.com')
sleep(2)
# 回退
browser.back()
# 前进
browser.forward()


sleep(5)
browser.quit()